// 云函数入口文件
const cloud = require('wx-server-sdk')
// 获取publish表格数据 展示在首页
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database();
const _ = db.command;
// 云函数入口函数
exports.main = async (event, context) => {
  // 最新活动最多就10条
  if(event.COUNT == 4){
    return db.collection('publish')
    .aggregate()
    .match({
      status:_.eq(0)
    })
    .project({
      peopleCount:0,
      registeredCount:0,
      content:0,
      host:0,
    })
    .sort({
      time:-1
    })
    .limit(event.COUNT)
    .end()
  }

  return db.collection('publish')
  .aggregate()
  .match({
    status:_.eq(0)
  })
  .project({
    peopleCount:0,
    registeredCount:0,
    content:0,
    host:0,
  })
  .sort({
    time:-1
  })
  .end()
}